<script lang="ts" setup>
import { onMounted, ref } from "vue";
import { delTable, postTable } from "@/api/apiJson";
import { ElMessage, ElMessageBox } from "element-plus";

defineOptions({
  name: "add"
});
const props = defineProps({
  params: {
    type: Object,
    default: () => {
      return {
        data: {},
        multipleSelection: []
      };
    }
  },
  from_config: {
    type: Object,
    required: true,
    default: () => {
      return {
        columns: []
      };
    }
  },
  businessCode: {
    type: String,
    required: true
  }
});
const visible = ref(true);
const emit = defineEmits(["search"]);

// ============================业务操作========================================

/**
 * 批量删除
 */
async function handleConfirm() {
  console.log(props.params.multipleSelection);
  const ids = [];
  props.params.multipleSelection.forEach((item: any) => {
    ids.push(item[`${props.businessCode}`].id);
  });
  if (!ids.length) {
    ElMessage({
      message: "请先选择要删除的数据",
      type: "info"
    });
    visible.value = false;
    return;
  }
  await delTable(props.businessCode, { "id{}": ids }).then(() => {
    ElMessage({
      message: "删除成功",
      type: "success"
    });
    visible.value = false;
    emit("search");
  });
}
</script>

<template>
  <PlusDialog
    v-model="visible"
    title="批量删除"
    cancel-text="取消"
    confirm-text="确定"
    @confirm="handleConfirm"
  >
    确认删除选中的数据吗？
  </PlusDialog>
</template>
